package me.zhengjie.modules.transfer.factory.service.Impl;

import lombok.RequiredArgsConstructor;
import me.zhengjie.modules.account.mapper.AccountCommonMapper;
import me.zhengjie.modules.transfer.factory.service.TransferPersonService;
import me.zhengjie.tool.BigDecimalUtil;
import me.zhengjie.tool.MyMap;
import me.zhengjie.tool.NPETool;
import me.zhengjie.tool.ValidateUtil;
import me.zhengjie.vo.Constant;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 转移人员基本信息实现类
 */
@Service
@RequiredArgsConstructor
public class TransferPersonServiceImpl implements TransferPersonService {

    private final AccountCommonMapper accountCommonMapper;

    /**
     * 组装转移人员信息
     * @param aac001
     * @param aae140
     * @return
     */
    @Override
    public MyMap getTransferPerson(String aac001, String aae140) {

        MyMap resultMap = new MyMap<>();
        NPETool.isEmptyThrowException(aac001, "人员编号");
        NPETool.isEmptyThrowException(aae140, "险种类型");

        Map param = new HashMap();
        param.put("aac001", aac001);
        param.put("aae140", aae140);
        param.put("aac320", Constant.AAC320_1_YX);
        param.put("aac008", Constant.AAC008_1_ZCCB);

        List<Map> ac01s = accountCommonMapper.getAc01(param);
        if (ValidateUtil.isEmpty(ac01s) || ac01s.size() > 1) {
            throw new IllegalArgumentException("获取人员基本信息异常");
        }
        Map map = ac01s.get(0);
        MyMap myMap = new MyMap(map);

        resultMap.put("aac001", myMap.getAsBigDecimal("aac001"));
        resultMap.put("aae140", aae140);
        resultMap.put("aac002", myMap.getAsString("aac002"));
        resultMap.put("aac003", myMap.getAsString("aac003"));
        resultMap.put("aac004", myMap.getAsString("aac004"));
        resultMap.put("aac006", myMap.getAsString("aac006"));
        if (!ValidateUtil.isEmpty(myMap.getAsBigDecimal("aac007"))) {
            resultMap.put("aac007", BigDecimalUtil.getBigDecimal(myMap.getAsBigDecimal("aac007").toString().substring(0, 6)));
        }

        resultMap.put("aac009",myMap.getAsString("aac009"));
        resultMap.put("aac010",myMap.getAsString("aac010"));
        resultMap.put("aac067",myMap.getAsString("aac067"));
        resultMap.put("aac028",myMap.getAsString("aac028"));
        resultMap.put("aaa027",myMap.getAsString("aaa027"));
        resultMap.put("aae473",myMap.getAsString("aae473"));

        List<Map> ac02s = accountCommonMapper.getAc02(param);
        if (ValidateUtil.isEmpty(ac02s) || ac02s.size() > 1) {
            throw new IllegalArgumentException("获取人员正常参保信息异常");
        }
        map = ac02s.get(0);
        myMap = new MyMap(map);
        resultMap.put("aaz159", myMap.getAsBigDecimal("aaz159"));

        resultMap.put("aac030", myMap.getAsString("aac030").replaceAll("-",""));
        resultMap.put("aab001", myMap.getAsBigDecimal("aab001"));
        resultMap.put("aae206", myMap.getAsString("aae206").replaceAll("-","").substring(0,6));
        resultMap.put("aab359", myMap.getAsString("aab359"));
        resultMap.put("aac049", myMap.getAsString("aac049").replaceAll("-",""));
        resultMap.put("aac305", myMap.getAsString("aac049").replaceAll("-",""));

        param.put("aab001", myMap.getAsString("aab001"));
        List<Map> ab01s = accountCommonMapper.getAb01(param);
        if (ValidateUtil.isNotEmpty(ab01s)) {
            resultMap.put("aab004", (String) ab01s.get(0).get("aab004"));
        }

        return resultMap;
    }

    /**
     * 信息表险种
     * @param aic113
     * @return
     */
    @Override
    public MyMap xxbAae140Aae241(String aic113) {

        NPETool.isEmptyThrowException(aic113,"养老保险转移制度方向");
        String aae140="";//转出
        String aae241="";//转入
        switch (aic113) {
            case Constant.AIC113_1_QYZGYLBXZDNZY:
                aae241=Constant.AAE140_110_QYZGJBYLBX;//转入
                aae140=Constant.AAE140_110_QYZGJBYLBX;//转出
                break;
            case Constant.AIC113_2_QYZGYLBXZDZJGSYDWYLBXZD:
                aae241=Constant.AAE140_120_JGSYDWGZRYJBYLBX;//转入
                aae140=Constant.AAE140_110_QYZGJBYLBX;//转出
                break;
            case Constant.AIC113_3_JGSYDWYLBXZDZQYZGYLBXZD:
                aae241=Constant.AAE140_110_QYZGJBYLBX;//转入
                aae140=Constant.AAE140_120_JGSYDWGZRYJBYLBX;//转出
                break;
            case Constant.AIC113_6_JGSYDWYLBXZDNZY:
                aae241=Constant.AAE140_120_JGSYDWGZRYJBYLBX;//转入
                aae140=Constant.AAE140_120_JGSYDWGZRYJBYLBX;//转出
                break;
            case Constant.AIC113_4_QYZGYLBXZDZCXJMJBYLZD:
                aae241=Constant.AAE140_170_CXJMJBYLBX;//转入
                aae140=Constant.AAE140_110_QYZGJBYLBX;//转出
                break;
            case Constant.AIC113_9_ZYNJZY:
                aae241=Constant.AAE140_180_ZYNJ;//转入
                aae140=Constant.AAE140_180_ZYNJ;//转出
                break;
            case Constant.AIC113_10_ZYNJZY:
                aae241=Constant.AAE140_120_JGSYDWGZRYJBYLBX;//转入
                aae140=Constant.AAE140_120_JGSYDWGZRYJBYLBX;//转出
                break;
            default:
                throw new IllegalArgumentException("没有获取到对应的转出类型！");
        }
        MyMap map = new MyMap<>();
        map.put("aae140",aae140);
        map.put("aae241",aae241);
        return map;

    }
}
